package com.lanou.sfu.songforu.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lanou.sfu.songforu.R;
import com.lanou.sfu.songforu.entity.SongMenuDetailEntity;

import java.util.List;

/**
 * Created by dllo on 15/10/31.
 */
public class SongMenuDetailAdapter extends BaseAdapter {
    private Context mContext;
    private List<SongMenuDetailEntity.ContentEntity> datas;

    public SongMenuDetailAdapter(Context context, List<SongMenuDetailEntity.ContentEntity> lists) {
        mContext = context;
        datas = lists;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public SongMenuDetailEntity.ContentEntity getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null){
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.songmenu_detail_listview_item,null);
            holder.artistName = (TextView) convertView.findViewById(R.id.songmenu_detail_item_artist_textView);
            holder.songName = (TextView) convertView.findViewById(R.id.songmenu_detail_item_song_textView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        SongMenuDetailEntity.ContentEntity contentEntity = getItem(position);
        Log.i("hhaa", contentEntity.getTitle() + "");
        if (contentEntity != null){
            holder.songName.setText(contentEntity.getTitle());
            holder.artistName.setText(contentEntity.getAuthor());
        }
        return convertView;
    }

    public class ViewHolder{
        private TextView songName,artistName;
    }
}
